import base64

import xlrd
from facade.mysqlfacade import MysqlUtiles
from xjlibrary.our_file_dir import BaseDir

curpath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curpath, "db.ini")

# 配置文件与默认配置文件key的转换
keytransformdicts = {"port": "db_port", "host": "db_host", "passwd": "db_pw", "user": "db_user",
                     "db": "db_name",
                     "chartset": "db_charset"}
# mysql 工具类
myutil = MysqlUtiles(configfile, "exceltosql", keytransformdicts=keytransformdicts)



wb = xlrd.open_workbook("F:\\test4\\test.xlsx")

sh = wb.sheet_by_index(0)

title = sh.row_values(0)

for rownum in range(1, sh.nrows):
    rowvalue = sh.row_values(rownum)
    dicts = {}
    dicts1 = {}
    for key, value in zip(title, rowvalue):
        dicts[key] = value
    print(dicts)
    user = dicts["账号"]
    password = dicts["密码"]
    j_username = base64.b64encode(user.encode("utf-8")).decode("utf-8")
    j_password = base64.b64encode(password.encode("utf-8")).decode("utf-8")
    sql = "insert ignore into user(`username`,`password`,`j_username`,`j_password`) values ('{}','{}','{}','{}')".format(user,password,j_username,j_password)
    myutil.ExeSqlToDB(sql)

print(base64.b64encode(b"xujiang58"))
s = "xujiang58"
b = s.encode("utf-8")
print(type(b))
print(base64.b64encode(b).decode("utf-8"))
# b'eHVqaWFuZzU4'
